const arr1 = [4, 2, 1, 8 , 7];

console.time("my-operation")
function quickSort(arr) {
    if (arr.length  <= 1) {
        return arr;
    }

    const pivotIndex = Math.floor(arr.length / 2);

    const pivot = arr.splice(pivotIndex,1)[0]; // 第一个参数是添加/删除元素的位置!
    // 第二个参数是进行操作的个数!

    const left = [],
        right = [];

    for (let i = 0; i < arr.length; i++) {
        if (arr[i] < pivot) {
            left.push(arr[i]);
        } else {
            right.push(arr[i]);
        }
    }

    return quickSort(left).concat([pivot], quickSort(right));

};

console.log(quickSort(arr1))
console.timeEnd("my-operation")
console.log("=====================")

console.time("bubblesort");
function bubbleSort(arr) {
    let temp, len = arr.length;
    for (let i = 0; i < len; i++) {
        for (let j = 0; j < len - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
    return arr
}
console.log(bubbleSort([4, 2, 1, 8 , 7]))
console.timeEnd("bubblesort")



console.log(Math.floor(3.8 / 2)); // 向下取整！

const arr12 = [4, 4, 4, 2, 1, 8 , 7];

const set = new Set(arr12);
ja
